package com.happyrecyclingstation.service.impl;

import com.happyrecyclingstation.mapper.ReportMapper;
import com.happyrecyclingstation.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
	@Autowired
	private ReportMapper reportMapper;

	/**
	 * 统计用户
	 * @return
	 */
	@Override
	public List<Map<String, Integer>> getUserCount() {
		return reportMapper.getUserCount();
	}

	/**
	 * 统计职位
	 * @return
	 */
	@Override
	public List<Long> getPositionCount() {
		// 1. 使用Object接收真实类型
		List<Map<String, Object>> listMap = reportMapper.getPositionCount();

		// 2. 初始化结果集
		List<Long> result = new ArrayList<>(Collections.nCopies(12, 0L));

		// 3. 安全处理数据
		for (Map<String, Object> monthData : listMap) {
			int month = ((Number) monthData.get("month")).intValue();
			long count = ((Number) monthData.get("count")).longValue();
			result.set(month - 1, count);
		}
		return result;
	}
}
